home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / C++ / MPW C++ 3.1b1 / Examples / CPlusExamples / TDocument.h < prev    next >
Text File  |  1989-09-29  |  5KB  |  146 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Application Framework
  6. #
  7. #    CPlusAppLib
  8. #
  9. #    TDocument.h        -    C++ source
  10. #
  11. #    Copyright © 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #            1.10                     07/89
  16. #            1.00                     04/89
  17. #
  18. #    Components:
  19. #            TApplicationCommon.h    July 9, 1989
  20. #            TApplication.h            July 9, 1989
  21. #            TDocument.h                July 9, 1989
  22. #            TApplication.cp            July 9, 1989
  23. #            TDocument.cp            July 9, 1989
  24. #            TApplication.r            July 9, 1989
  25. #
  26. #    CPlusAppLib is a rudimentary application framework
  27. #    for C++. The applications CPlusShapesApp and CPlusTESample
  28. #    are built using CPlusAppLib.
  29. #
  30. ------------------------------------------------------------------------------*/
  31.  
  32. #ifndef TDocument_Defs
  33. #define TDocument_Defs
  34.  
  35. // Include necessary interface files
  36. #include <Types.h>
  37. #include <QuickDraw.h>
  38.  
  39. // Define HiWrd and LoWrd macros for efficiency
  40. #define HiWrd(aLong)    ((short) (((aLong) >> 16) & 0xFFFF))
  41. #define LoWrd(aLong)    ((short) ((aLong) & 0xFFFF))
  42.  
  43. // Define TopLeft and BotRight macros for convenience. Notice the implicit
  44. // dependency on the ordering of fields within a Rect
  45. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  46. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  47.  
  48. const long kMaxSleepTime = 60;    // 1 second worth of ticks
  49.  
  50. // we derive from handle object to prevent fragmentation
  51. class TDocument : HandleObject {
  52. protected:
  53.     WindowPtr fDocWindow;
  54.  
  55. public:
  56.     TDocument(short resID);        // our constructor - creates window using resID as template
  57.     virtual ~TDocument();        // our destructor - disposes of window
  58.  
  59.     // you will need to override these in your subclasses,
  60.     // since they are do-nothing routines by default...
  61.     virtual void DoZoom(short partCode) {}
  62.     virtual void DoGrow(EventRecord* theEvent) {}
  63.     virtual void DoContent(EventRecord* theEvent) {}
  64.     virtual void DoKeyDown(EventRecord* theEvent) {}
  65.     virtual void DoActivate(Boolean becomingActive) {}
  66.     virtual void DoUpdate(void) {}
  67.     // file handling routines
  68.     virtual void DoOpen(void) {};
  69.     virtual void DoClose(void) { delete this; };    // by default, we just delete ourself & let destructor do cleanup
  70.     virtual void DoSave(void) {};
  71.     virtual void DoSaveAs(void) {};
  72.     virtual void DoRevert(void) {};
  73.     virtual void DoPrint(void) {};
  74.     // do standard edit menu actions
  75.     virtual void DoUndo(void) {};
  76.     virtual void DoCut(void) {};
  77.     virtual void DoCopy(void) {};
  78.     virtual void DoPaste(void) {};
  79.     virtual void DoClear(void) {};
  80.     virtual void DoSelectAll(void) {};
  81.  
  82.     // idle time routines: you can use these to do cursor handling,
  83.     // TE caret blinking, marquee effects, etc...
  84.     virtual void DoIdle(void) {};
  85.     virtual unsigned long CalcIdle(void) { return kMaxSleepTime; };    // by default, we don't need idle
  86.     virtual void AdjustCursor(Point where) {};            // where is in local coords
  87.  
  88.     // query state of document - useful for adjusting menu state
  89.     virtual Boolean HaveUndo(void) { return false; };
  90.     virtual Boolean HaveSelection(void) { return false; };
  91.     virtual Boolean HavePaste(void) { return false; };
  92.     virtual Boolean CanClose(void) { return true; };
  93.     virtual Boolean CanSave(void) { return false; };
  94.     virtual Boolean CanSaveAs(void) { return true; };
  95.     virtual Boolean CanRevert(void) { return false; };
  96.     virtual Boolean CanPrint(void) { return false; };
  97.  
  98.     // utility routine to get window pointer for document
  99.     inline WindowPtr GetDocWindow(void) { return fDocWindow; }
  100. };
  101.  
  102. // TDocumentLink is a simple utility class which is used by
  103. // the TDocumentList class below. You cannot allocate
  104. // objects of this type yourself, since its constructor
  105. // is private. We get around this for TDocumentList by
  106. // making it a "friend" of this class. This is a handy
  107. // trick.
  108. class TDocumentLink {
  109.     friend class TDocumentList;
  110.  
  111.     TDocumentLink*            fNext;    // the link to the next document
  112.     TDocument*                fDoc;    // the document this link refers to
  113.  
  114.     // our constructor. Note that it can take args for convenience,
  115.     // but that they default to nil.
  116.     TDocumentLink(TDocumentLink *n = nil, TDocument *v = nil);
  117.  
  118.     // implementation of our TDocumentLink routines is done inline, for speed
  119.     inline TDocumentLink*    GetNext() { return fNext; };
  120.     inline TDocument*         GetDoc() { return fDoc; };
  121.     inline void                SetNext(TDocumentLink* aLink) { fNext = aLink; };
  122.     inline void             SetDoc(TDocument* aDoc) { fDoc = aDoc; };
  123. };
  124.  
  125. // TDocumentList is a simple linked list of documents, implemented C++
  126. // style. I could have made a general linked list class & just made
  127. // this a subclass. This would have been a more general (and more
  128. // object-oriented) solution, but I did it from scratch in a futile
  129. // attempt at keeping the size of this program at a reasonable level.
  130. class TDocumentList {
  131.     TDocumentLink*    fDocList;    // the first link in our list
  132.     int                fNumDocs;    // the number of elements in the list
  133.  
  134. public:
  135.     TDocumentList(void);    // our constructor
  136.  
  137.     virtual void        AddDoc(TDocument* doc);
  138.     virtual void        RemoveDoc(TDocument* doc);
  139.     // find the TDocument associated with the window
  140.     virtual TDocument*    FindDoc(WindowPtr window);
  141.     // return number of active documents
  142.     inline int            NumDocs() { return fNumDocs; }
  143. };
  144.  
  145. #endif TDocument_Defs
  146.